<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>待发布商品</title>
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                                <tr>
                                    <td>
                                        <span>商家编码：<input type="text" id="product_code" name="product_code" value="" style="width:120px;"/></span>
                                        <span>商品名称：<input type="text" id="goodsName" name="goodsName" maxlength="80" value="" style="width:300px;"/></span>
                                        <span>销售价：<input type="text" id="startPrice" name="startPrice" value="" style="width:60px;"/> ～<input type="text" id="endPrice" name="endPrice" value="" style="width:60px;"/></span>
                                        <span style="vertical-align:middle;">
                                        	<span style="float: left;display:inline-block;padding-top:1px;">商品分类：</span>
                                        	<!--{$goodsInfo->category}-->
                                        </span>
                                        <span style="clear: both;"></span>
                                        <br/>
                                        <span>
                                            品牌：
                                            <select style="width:120px;" id="brandID" name="brandID">
                                                <option value="0">请选择</option>
                                                <!--{foreach from=$goodsInfo->brandList item=b_l}-->
                                                <option value="<!--{$b_l->brandID}-->"><!--{$b_l->brandName}--></option>
                                                <!--{/foreach}-->
                                            </select>
                                        </span>
                                        <span>
                                            上架状态：
                                                    <select style="width:120px;" id="forsale" name="forsale">
                                                        <option value="0">请选择</option>
                                                        <option value="1">上架</option>
                                                        <option value="2">下架</option>
                                                    </select>
                                        </span>
                                        <span>
                                            同步状态：
                                                    <select style="width:120px;" id="isPublish" name="isPublish">
                                                        <option value="0">请选择</option>
                                                        <option value="1">已发布</option>
                                                        <option value="2">未发布</option>
                                                    </select>
                                        </span>
                                        <span><input type="button" value="查询" class="btn" onclick="goods.search();" /></span>
                                        <span><input type="button" value="重置" class="btn" onclick="reset();" /></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>


<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=1&xjx=none",
        dataType: "json",
        colModel : [
        {display: "操作", width : 90, align: "center"},
        {display: "商家编码", width : 120, align: "left"},
        {display: "上架状态",width : 90},
        {display: "同步状态",width : 90},
        {display: "商品名称", width : 380},
        {display: "大分类", width : 90 },
        {display: "中分类", width : 90},
        {display: "小分类", width : 90},
        {display: "市场价", width : 90},
        {display: "销售价", width : 90}
        ],
        <!--{if $edit_permission}-->
        buttons : [
        	{name: "全选/全不选", onpress : "goods.selectAll"},
            {name: "批量预上架", onpress : "goods.upForsale"},
            {name: "批量预下架", onpress : "goods.downForsale"},
            {name: "批量同步", onpress : "goods.toSale"}
        ],
        <!--{/if}-->
        sortname: "timeStamp",
        sortorder: "desc",
        usepager: true,
        rp: 20,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            $(".bDiv").height('600');
            return true;
        }
    });

    //重置
    function reset(){
        $("#product_code").val('');
        $("#goodsName").val('');
        $("#startPrice").val('');
        $("#endPrice").val('');
        $("#bigCate").val(0);
        $("#midCate").val(0);
        $("#smallCate").val(0);
        $("#brandID").val(0);
    }
    
    
    var goods = {
        postID_str  : "" ,
        do_flg 	    : 0  ,
		allFlg		: 0 ,
        //商品列表
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //商品详情
        details: function(postID) {
            E.open("/quanliadmin/app/goods/goodsEdit.pscript?operFlg=2&postID=" + postID , "", {height: 600,width: 1062, top: 50, left: 150});
        },
        
        //打印弹出层
        printLayer : function(postID){
        	if(E.isDigital(postID)){
        		//ajax
        		$.ajax({
        			url : '/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=12&postID=' + postID,
        			type : 'POST',
        			dataType : 'JSON',
        			success : function(result){
        				//组装HTML
        				if(result.code == 200){
        					 E.popup.open({
				                title: "商品打印",
				                content: result.message,
				                btnName: "打印",
				                css: "min-width:680px;",
				                btnCall: ""
				            });
        					
        				}else
        					E.alert(result.message);
        			}
        		});
        	}
        },
        
        printAll : function(){
        	if(goods.allFlg == 0){
				$("[id ^='goodsChk_']").attr("checked","checked");
				goods.allFlg = 1;
			}else {
				$("[id ^='goodsChk_']").removeAttr("checked");
				goods.allFlg = 0;
			}
        },

        load: function() {
            $("#flex").flexReload();
        },
        
        //商品上架
		upForsale: function() {
			this.postID_str = "";
			this.do_flg	  = 1 ;
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    goods.postID_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.postID_str == ""){
                E.alert("请选择要上架的商品");
                return false ;
            }
            
            goods.doConfirm() ;
            
        },
        //商品下架
		downForsale: function() {
			this.do_flg	    = 0 ;
			this.postID_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    goods.postID_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.postID_str == ""){
                E.alert("请选择要下架的商品");
                return false ;
            }
            
           	E.confirm("您确认要下架选中的商品吗？", "goods.doConfirm");

        },
        toSale: function() {
			this.do_flg	    = 3 ;
			this.postID_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    goods.postID_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.postID_str == ""){
                E.alert("请选择要同步的商品");
                return false ;
            }
            
           	E.confirm("您确认要同步选中的商品吗？", "goods.doConfirm");
        },
        //上架确认
        doConfirm : function () {
        	E.loadding.open();
        	if(this.do_flg == 3)
        		var usrlink = "/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=9&postID_str=" + goods.postID_str  ;
        	else
        		var usrlink = "/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=8&postID_str=" + goods.postID_str + "&forsale=" + this.do_flg ;
			
            $.ajax({
                type: "POST",
                url: usrlink ,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                    	goods.allFlg = 0 ;
                        E.alert(result_obj.message, 2, "goods.load");
                        E.loadding.close();
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        	
        },
        allFlg:0 ,
        selectAll : function () {
        	if(goods.allFlg == 0){
        		$("[id ^='row']").addClass("trSelected");
        		goods.allFlg = 1 ;
        	}else{
        		$("[id ^='row']").removeClass("trSelected");
        		goods.allFlg = 0 ;
        	}
        }
        
    }; 
</script>
</body>
</html>